﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using s2b.ControleDesenvolvimentoProjetos.Util.Auxiliar;
using s2b.ControleDesenvolvimentoProjetos.Dados.OBJ;

namespace s2b.ControleDesenvolvimentoProjetos.Paginas
{
    public partial class WFAtribuirTarefa : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["ID_TAREFA"] != null)
            {

                if (!IsPostBack)
                {
                    ddlFuncionario.Items.Add(new ListItem() { Text = "Selecione", Value = "0" });




                    SqlDataReader executa = Auxiliar.RetornaRegistros("SELECT * FROM FUNCIONARIO", Funcionario.Tabela);
                    if (executa != null)
                    {
                        while (executa.Read())
                        {
                            string nomeFunc = String.Format("{0} {1}", executa["NOME_FUNC"].ToString(), executa["SOBRE_NOME"].ToString());
                            ddlFuncionario.Items.Add(new ListItem() { Text = nomeFunc, Value = executa["ID_FUNC"].ToString() });

                        }
                    }
                    executa = Auxiliar.RetornaRegistros(String.Format("SELECT * TAREFAS WHERE ID_TAREFA = {0}", Request.QueryString["ID_TAREFA"]), Funcionario.Tabela);
                    if (executa != null)
                    {
                        while (executa.Read())
                        {
                            lblTarefa.Text = executa["NOME_TAREFA"].ToString();

                        }
                    }


                }
             
            }
        }

        protected void btnAtribuirTarefa_Click(object sender, EventArgs e)
        {
        Auxiliar.ExecutaComando(String.Format("UPDATE TAREFAS SET ID_FUNC = {0} WHERE ID_TAREFA = {1}", ddlFuncionario.SelectedValue, Request.QueryString["ID_TAREFA"]));
            Response.Redirect("/Paginas/WFBacklog.aspx", false);
        
        }

        protected void ddlFuncionario_SelectedIndexChanged(object sender, EventArgs e)
        {

            Auxiliar.RetornaTabela(GridView1, Funcionario.Tabela, String.Format(@"SELECT     C.RAZAO_SOCIAL AS Cliente, P.NOME_PROJETO AS Projeto, T.NOME_TAREFA AS Tarefa
FROM         TAREFAS AS T INNER JOIN
                      PROJETO AS P ON P.ID_PROJETO = T.ID_PROJETO INNER JOIN
                      CLIENTE AS C ON C.ID_CLIENTE = P.ID_CLIENTE WHERE ID_FUNC = {0}", ddlFuncionario.SelectedValue));

        }
    }
}